package cn.wzby;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Reg6 {
    public static void main(String[] args) {
        String s = """
                <div>hello</div><div>java18 15</div><div><p>java 15</p><span>java 8</p><div>myjava 22html</div></div>
                <div>javascript</div>
                <div>java</div>
                <p>java</p>
                """;
        Pattern p = Pattern.compile("<div>[a-zA-Z 0-9]*?java[a-zA-Z 0-9]*?</div>");
        Matcher m = p.matcher(s);
        while(m.find()){
            System.out.println(m.group());
        }
        //将字符串中的java修改为php
        //将div标签中的java修改为php
        Pattern p1 = Pattern.compile("(<div>[a-zA-Z 0-9]*?)(java)([a-zA-Z 0-9]*?</div>)");
        System.out.println("================");
        System.out.println(s);
        System.out.println("================");
        System.out.println(s.replaceAll(p1.toString(),"$1php$3"));
        System.out.println(s.replaceAll("(<div>[a-zA-Z 0-9]*?)(java)([a-zA-Z 0-9]*?</div>)","$1php$3"));
    }
}
